// pages/index_new/index_new.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img:"https://lgn.xiangxueweilai.com/public/images/mofang.png",
    user:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   var sat = wx.getStorageSync('user');
   var openid = wx.getStorageSync('openid');

    console.log(sat);
    
   if(!sat){
     wx.redirectTo({
       url: '/pages/getuser/getuser',
     })
   }else{
     //存储到数据库中去
     wx.request({
       url: 'https://lgn.xiangxueweilai.com/index.php/setUserMsg ',
       method: "POST",
       data: { "nickname": sat.nickName, "openid": openid, "avatar": sat.avatarUrl},
       header: {
         'content-type': 'application/x-www-form-urlencoded'
       },
       complete() {
         wx.hideLoading()
       },
       success: res => {
          console.log(res);
       }
     })
   }
  },

  click_dump:function(e){
    let itmeid = e.currentTarget.dataset.itme;
    wx.navigateTo({
      url: "/pages/list/list?itemid=" + itmeid
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.showLoading({
      title: '登录中'
    })

    
     
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: 'https://lgn.xiangxueweilai.com/index.php/cateName',
      method: "post",
      data: {},
      header: {
        'content-type': 'application/json' // 默认值
      },
      complete() {
        wx.hideLoading()
      },
      success: res => {
        that.setData({
          cate_arr: res.data.result
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})